<script type="text/javascript">
		Yutil.useLoadingMessage();
		Yutil.en.enhance();
</script>
<%	
		String employeeInServiceCreate = request.getParameter("employeeid_service_create");
		System.out.println(employeeInServiceCreate + "----------------employeeInServiceCreate");
%>

<p></p>

<fieldset class="form"  id="service_create_form">
		<table align="left">
			<tr>
				<td>
					<!-- 
					Hi mengc, I don't know why here need the name attribute " ' ",but not " " ".
					When I use ", there will be one defect.
					 -->
					开始日期：<input id="salaryServiceStartDate" type="text" name='salaryServiceStartDate' value="" class=" date"/><br/>
				</td>
			</tr>
			<tr>
				<td>
					结束日期：<input id="salaryServiceEndDate" type="text" name='salaryServiceEndDate' value="" class=" date"/><br/>
				</td>
			</tr>
		</table>
		<br/><p></p>
		<div class="hrule-dots"></div>
		
		<table align="left">
			<tr>
				<th>基本工资</th>
				<td><input id="baseWage" name="baseWage" class="number" onkeyup="calculateFormValue(this)"/></td>
			</tr>
			<tr>
				<th>保险金基数</th>
				<td><input id="insuranceBase" name="insuranceBase" class="number"/></td>
			</tr>
			<tr>
				<th>公积金基数</th>
				<td><input id="housingfundBase" name="housingfundBase" class="number"/></td>
			</tr>
			<!-- some inputs need child page input -->
			<input type="hidden" id="insurance_value"/>
			<input type="hidden" id="housingfund_value"/>
			<input type="hidden" id="incometax_value"/>
		</table>
		<div class="hrule-dots"></div>
		
		<table align="left">
			<tr>
				<td>
					<ul class="tree">
							<li><span>保险服务</span>
									<ul>
											<li>
<table>
	<tr>
		<th>EmployeeId_Name</th>
		<th>养老保险金</th>
		<th>医疗保险金</th>
		<th>失业保险金</th>
		<th>工伤保险金</th>
		<th>生育保险金</th>
	</tr>
	<tr>
		<th>单位缴纳数</th>
		<td>
			<input id="endowment_enterprise" name="endowment_enterprise" class="number"/><small>(22%)</small>
			<input id="endowment_enterprise_rate" value="<%= FinancialRateService.$.getEndowmentRATE_C(employeeInServiceCreate)%>" type="hidden"/>
		</td>
		<td>
			<input id="medical_enterprise" name="medical_enterprise" class="number"/><small>(12%)</small> 
			<input id="medical_enterprise_rate" value="<%= FinancialRateService.$.getMedicalRATE_C(employeeInServiceCreate)%>" type="hidden"/> 
		</td>
		<td>
			<input id="suspension_enterprise" name="suspension_enterprise" class="number"/><small>(2%)</small>
			<input id="suspension_enterprise_rate" value="<%= FinancialRateService.$.getSuspensionRATE_C(employeeInServiceCreate)%>" type="hidden"/> 
		</td>
		<td>
			<input id="workplace_enterprise" name="workplace_enterprise" class="number"/><small>(0.5%)</small>
			<input id="workplace_enterprise_rate" value="<%= FinancialRateService.$.getWorkplaceRATE_C(employeeInServiceCreate)%>" type="hidden"/> 
		</td>
		<td>
			<input id="maternity_enterprise" name="maternity_enterprise" class="number"/><small>(0.5%)</small>
			<input id="maternity_enterprise_rate" value="<%= FinancialRateService.$.getMaterntiyRATE_C(employeeInServiceCreate)%>" type="hidden"/>  
		</td>
	</tr>
	<tr>
		<th>个人缴纳数</th>
		<td>
			<input id="endowment_employee" name="endowment_employee" class="number"/><small>(8%)</small>
			<input id="endowment_employee_rate" value="<%= FinancialRateService.$.getEndowmentRATE_E(employeeInServiceCreate)%>" type="hidden"/>
		</td>
		<td>
			<input id="medical_employee" name="medical_employee" class="number"/><small>(2%)</small>
			<input id="medical_employee_rate" value="<%= FinancialRateService.$.getMedicalRATE_E(employeeInServiceCreate)%>" type="hidden"/> 
		</td>
		<td>
			<input id="suspension_employee" name="suspension_employee" class="number"/><small>(1%)</small>
			<input id="suspension_employee_rate" value="<%= FinancialRateService.$.getSuspensionRATE_E(employeeInServiceCreate)%>" type="hidden"/> 
		</td>
		<td></td>
		<td></td>
	</tr>
	<tr>
		<th>单位缴纳总数</th>
	</tr>
</table>
											</li>
									</ul>
							</li>
					</ul>
				</td>
			</tr>
			<tr>
				<td>
					<ul class="tree">
							<li><span>公积金服务</span>
									<ul>
											<li>
<table>
	<tr>
		<th>EmployeeId_Name</th>
		<th>基本住房公积金</th>
		<th>补充住房公积金</th>
	<tr>
	<tr>
		<th>单位缴纳数</th>
		<td>
			<input id="housingfund_enterprise" name="housingfund_enterprise" class="number"/><small>(7%)</small>
			<input id="housingfund_enterprise_rate" value="<%= FinancialRateService.$.getHousingfundRATE_C(employeeInServiceCreate)%>" type="hidden"/>
		</td>
		<td></td>
	</tr>
	<tr>
		<th>个人缴纳数</th>
		<td>
			<input id="housingfund_employee" name="housingfund_employee" class="number"/><small>(7%)</small>
			<input id="housingfund_employee_rate" value="<%= FinancialRateService.$.getHousingfundRATE_E(employeeInServiceCreate)%>" type="hidden"/>
		</td>
		<td></td>
	</tr>
</table>
											</li>
									</ul>
							</li>
					</ul>
				</td>
			</tr>
			<tr>
				<td>
					<ul class="tree">
							<li><span>所得税服务</span>
									<ul>
											<li>
<table>
	<tr>
		<th>扣除保险金与公积金后工资</th>
		<td><input id="beforetax_salary" name="beforetax_salary" class="number" value=""/></td>
	</tr>
	<tr>
		<th>个人所得税</th>
		<td><input id="incometax" name="incometax" class="number" value=""/></td>
	</tr>
	<tr>
		<th>税后工资</th>
		<td>
			<input id="aftertax_salary" name="aftertax_salary" class="number"/>
		</td>
	</tr>

</table>
											</li>
									</ul>
							</li>
					</ul>
				</td>
			</tr>
		</table>
		<br/><p></p>
		<div class="hrule-dots"></div>
		<p>
			<input class="button" type="button" value="保存" onclick="saveService(this)"/>
			<input class="button" type="button" value="取消" onclick="cancelCreateService()"/>
			<input class="button" type="button" value="重置" onclick="resetCreateService()"/>
		</p>
</fieldset>

<script type="text/javascript">
	cancelCreateService = function() {
		Yutil.hideDialog("serviceCreateDialog");
	}

	resetCreateService = function() {
		var pars = 'employeeid_service_create=' + '<%= employeeInServiceCreate%>';
				var url = 'la_service_create.jsp';
				var myAjax = new Ajax.Updater('serviceCreateDialog_content',url,{method:'get', parameters: pars,  evalScripts: true});
	}
	
	saveService = function(btn) {
		var url = "/" + "<%= LocalContants.PROJECT_NAME %>" + "/serviceCreate.do";
		var serviceCreateForm = $('service_create_form');
		var pars = Form.serialize(serviceCreateForm) + '&employeeid=' + "<%= employeeInServiceCreate%>";
		if(Yform.validateAllOnSubmit(btn)) {
				var myAjax = new Ajax.Updater("right",url,{method:'post',parameters: pars, evalScripts:true});
				Yutil.hideDialog("serviceCreateDialog");
		}	
	}

	// copy from f_insuranceAndHousingfund_calculate.jsp
	// Jetty Yang  
	//    distract: dight要格式化的数字，mun要保留的小数位数。  
	distract = function(digit, num)  
	{  
		digit  =  Math.round(digit * Math.pow(10, num)) / Math.pow(10,num);  
        return  digit;  
	}  

	calculateFormValue = function(oElem) {
		if(!Yform.validate(oElem))
			return;
		var baseWage = $('baseWage').value;
		//calculate base
		$('insuranceBase').value = baseWage;
		$('housingfundBase').value = baseWage;
		
		calculateInsurance();
		calculateHousingfund();
		calculateIncometax();		
	}
	
	//calculateInsurance
	calculateInsurance = function() {
		var baseWage = $('insuranceBase').value;
		
		//enterprise
		$('endowment_enterprise').value = distract(baseWage * parseInt($('endowment_enterprise_rate').value) / 100, 2);
		$('medical_enterprise').value = distract(baseWage * parseInt($('medical_enterprise_rate').value) / 100, 2);
		$('suspension_enterprise').value = distract(baseWage * parseInt($('suspension_enterprise_rate').value) / 100, 2);
		$('workplace_enterprise').value = distract(baseWage * Number($('workplace_enterprise_rate').value) / 100, 2);
		$('maternity_enterprise').value = distract(baseWage * Number($('maternity_enterprise_rate').value) / 100, 2);
		
		//employee
		$('endowment_employee').value = distract(baseWage * parseInt($('endowment_employee_rate').value) / 100, 2);
		$('medical_employee').value = distract(baseWage * parseInt($('medical_employee_rate').value) / 100, 2);
		$('suspension_employee').value = distract(baseWage * parseInt($('suspension_employee_rate').value) / 100, 2);
		
		$('insurance_value').value = Number($('endowment_employee').value) 
								   + Number($('medical_employee').value)
								   + Number($('suspension_employee').value);
	}
	
	calculateHousingfund = function() {
		var baseWage = $('housingfundBase').value;
		
		//enterprise
		$('housingfund_enterprise').value = distract(baseWage * parseInt($('housingfund_enterprise_rate').value) / 100, 2);
		
		//employee
		$('housingfund_employee').value = distract(baseWage * parseInt($('housingfund_employee_rate').value) / 100, 2);
		
		$('housingfund_value').value = Number($('housingfund_employee').value);
	}
	
	calculateIncometax = function() {
		//calculate the before tax salary
		$('beforetax_salary').value = distract(Number($('insuranceBase').value) - Number($('insurance_value').value) - Number($('housingfund_value').value), 2);
		
		//calculate the income tax
		//salary * rate - (Quick calculation deduction)
		var salary = Number($('beforetax_salary').value);
		var incometax = 0;
		var taxrate = 0;
		var qcd = 0;
		if(salary < 500) {
			taxrate = 5;
			qcd = 0;
		} else if(salary >=500 && salary < 2000) {
			taxrate = 10;
			qcd = 25;
		} else if(salary >=2000 && salary < 5000) {
			taxrate = 15;
			qcd = 125;
		} else if(salary >=5000 && salary < 20000) {
			taxrate = 20;
			qcd = 375;
		} else if(salary >=20000 && salary < 40000) {
			taxrate = 25;
			qcd = 1375;
		} else if(salary >=40000 && salary < 60000) {
			taxrate = 30;
			qcd = 3375;
		} else if(salary >=60000 && salary < 80000) {
			taxrate = 35;
			qcd = 6375;
		} else if(salary >=80000 && salary < 100000) {
			taxrate = 40;
			qcd = 10375;
		} else if(salary >=80000 && salary < 100000) {
			taxrate = 45;
			qcd = 15375;
		} 
		incometax = salary * taxrate / 100 - qcd;
		$('incometax').value = distract(incometax, 2);
		$('aftertax_salary').value = distract(salary - incometax, 2);
	}
	
</script>

<%@ page import="com.esms.struts.service.JspWidget" %> 
<%@ page import="java.util.*" %>
<%@ page import="com.esms.bean.Employee" %>
<%@ page import="com.esms.struts.service.*" %>
<%@ page language="java" contentType="text/html; charset=utf-8" %>